<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\common\controller\order\Orderget;
/*
*   后台操作日志控制器
*   July  2019-03-05
*/
class Log extends Controller
{
    public function __construct()
    {
        parent::__construct();

        //输出系统信息
        $systemInfo = (new System())->getSystemInfo();
        //获取充值总额
        $systemInfo['sumCharge'] = db('sys_charge')->where(['Status' => 1])->sum('Money');
        //获取消费总额
        $systemInfo['cost'] = db('docking_log')->sum('Price');
        //计算剩余金额
        $systemInfo['surplus'] = $systemInfo['sumCharge'] - $systemInfo['cost'];

        if($systemInfo['surplus'] < $systemInfo['BalanceInterval']){
            $isAlert = true;
        }else{
            $isAlert = false;
        }
        $this->assign('isAlert',$isAlert);
        $this->assign('systemInfo',$systemInfo);
    }

    //日志列表
    public function index(){
        return $this->fetch();
    }
    //获取数据 查询数据
    public function get_list(){
        $page = input('page');//分页
		$limit = input('limit');//显示个数
		$Orderget=new Orderget();
		$where=$Orderget->sorch();
        $data=Db::table('xb_sys_log')->page($page,$limit)->order('ID desc')->where($where)->select();
		$UserID=session('id');
		$RoleID=Db::table('xb_sys_administrator')->where(['ID'=>$UserID])->value('RoleID');
		if($RoleID!='1'){
			foreach ($data as $k => $v) {
				$RoleID=Db::table('xb_sys_administrator')->where(['ID'=>$v['UserID']])->value('RoleID');
				if($RoleID=='1'){
					unset($data[$k]);
				}
			}
		}	
        $count=Db::table('xb_sys_log')->where($where)->count('ID');   
        if($data){
           songsong($data,$count);  
        }else{
            songsong();
        }
    }







}
